import axios from 'axios'
// 创建一个网络请求实例
const service = axios.create({
  // 如果你设置了baseURL,则代理会失效，请求是全地址则，代理生效
  baseURL: process.env.NODE_ENV === 'development' ? '' : 'https://api.iynn.cn/film',
  timeout: process.env.NODE_ENV === 'development' ? 5000 : 10000
})
// 响应拦截器
service.interceptors.response.use(response => {
  if (response.status >= 200 && response.status < 300) {
    return response.data
  } else {
    return Promise.reject('error')
  }
}, err => Promise.reject(err))

export const get = (url, config = {}) => service.get(url, config)
export const post = (url, data = {}, config = {}) => service.post(url, data, config)